package com.hjl.service.role;

import com.hjl.dao.role.RoleMapper;
import com.hjl.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

/*    public RoleMapper getRoleMapper() {
        return roleMapper;
    }

    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }*/

    @Override
    public List<Role> getListInfo(String roleName) {
        try {
            return roleMapper.getListInfoByName2(roleName);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int addInfos(Role role) {
        int count = 0;
        try {
            count = roleMapper.add(role);
            return count;
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int updateRoleInfoById(Role role) {

        try {
            return roleMapper.updateRoleInfoById(role);
        } catch (RuntimeException e) {
            e.printStackTrace();
            throw e;
        }
    }

    @Override
    public int totalCount(Integer userRole) {

        int count = roleMapper.totalCount(userRole);

        return count;
    }

    @Override
    public int deleteUserInfo(Integer userRole) {
        return roleMapper.deleteUserInfo(userRole);
    }

    @Override
    public int deleteRoleInfos(Integer id) {
        return roleMapper.deleteRoleInfos(id);
    }
}
